package com.qf.controller;

import com.qf.pojo.DtsAdmin;
import com.qf.service.DtsBrandService;
import com.qf.service.DtsCommentService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/comment")
public class DtsAdminCommentController {
    @Autowired
    DtsBrandService brandService;

    @Autowired
    DtsCommentService commentService;

    @PostMapping("/delete")
    public Object delete(Integer id){
        commentService.delete(id);
        return ResponseUtil.ok();
    }

    @GetMapping("/list")
    public Object list(@RequestParam(value = "page",required = false, defaultValue = "1") Integer page,
                       @RequestParam(value = "limit",required = false, defaultValue = "20") Integer limit,
                       Integer userId , Integer valueId, String sort, String order) {

        Subject subject = SecurityUtils.getSubject();
        DtsAdmin admin = (DtsAdmin) subject.getPrincipal();
        List<Integer> brandIds = null;

        if(subject.hasRole("品牌制造商")){
            brandIds = brandService.findBrandId(admin.getId());
        }
        Map<String,Object> data = commentService.Page(page,limit, userId, valueId, sort, order, brandIds);
        return ResponseUtil.ok(data);
    }
}